/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package me.minetsh.imaging.view;

import me.minetsh.imaging.imageData.UriUtils;
import ohos.app.Context;
import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;
import ohos.utils.net.Uri;

/**
 * PhotoUtil
 *
 * @since 2021-07-27
 */
public class PhotoUtil {
    /**
     * 根据uri String 获取PixelMap
     *
     * @param context 上下文
     * @param strUri uriString
     * @return PixelMap
     */
    public static PixelMap getPixelMapByUri(Context context, String strUri) {
        Uri uri = Uri.parse(strUri);
        ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions();
        ImageSource imageSource = UriUtils.uriToImageSource(context, uri);
        PixelMap orgPixelMap = imageSource.createPixelmap(decodingOptions);
        return orgPixelMap;
    }

    /**
     * 根据uri 获取PixelMap
     *
     * @param context 上下文
     * @param uri Uri
     * @return PixelMap
     */
    public static PixelMap getPixelMapByUri(Context context, Uri uri) {
        ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions();
        ImageSource imageSource = UriUtils.uriToImageSource(context, uri);
        PixelMap orgPixelMap = imageSource.createPixelmap(decodingOptions);
        return orgPixelMap;
    }
}
